<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>搜索引擎的词联想功能</title>
    <style type="text/css">
        /*TODO 怎么显示不出来*/
        input{
            border: 1px solid #ff0000;
            padding: 4px 8px;
            min-width: 300px;
            height: 40px;
            font-size: 14px;
            display: block;
            margin: 0 auto;
            outline: orange;
        }
        .result{
            text-align: center;
        }
    </style>
</head>
<body>
    <div>
        <intput type="text"></intput>
        <div class="result"></div>
    </div>

    <script>
        var input = document.querySelector('input');
        var result = document.querySelector('.result');
        var timer = null;

        input.addEventListener('input', function(e) {
            clearTimeout(timer);

            timer = setTimeout(function() {
                var val = e.target.value;

                result.innerText = '联想内容：' + val;
            }, 300);
        });
    </script>
</body>
</html>